package org.way.base.dto;

import lombok.Data;

import java.io.Serializable;
import java.util.List;

@Data
public class GlobalDTO<T> implements Serializable {

    private Integer code = 0;

    private String msg;

    private T data;

    private Long count = 0L;

    public static <T> GlobalDTO<T> error(String msg) {
        GlobalDTO<T> dto = new GlobalDTO<>();
        dto.setMsg(msg);
        return dto;
    }

    public static <T> GlobalDTO<T> success(T data) {
        GlobalDTO<T> dto = new GlobalDTO<>();
        dto.setData(data);
        return dto;
    }

    public static <T> GlobalDTO<List<T>> page(List<T> data,Long count) {
        GlobalDTO<List<T>> dto = new GlobalDTO<>();
        dto.setData(data);
        dto.setCount(count);
        return dto;
    }

    public static <T> GlobalDTO<T> success() {
        GlobalDTO<T> dto = new GlobalDTO<>();
        return dto;
    }
}
